package com.sq.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sq.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sq.common.annotation.Log;
import com.sq.common.core.controller.BaseController;
import com.sq.common.core.domain.AjaxResult;
import com.sq.common.enums.BusinessType;
import com.sq.activity.domain.ActivityRegistration;
import com.sq.activity.service.IActivityRegistrationService;
import com.sq.common.utils.poi.ExcelUtil;
import com.sq.common.core.page.TableDataInfo;

/**
 * 活动报名Controller
 * 
 * @author shan
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/activity/registration")
@Api(tags = "活动报名相关接口")
public class ActivityRegistrationController extends BaseController
{
    @Autowired
    private IActivityRegistrationService activityRegistrationService;

    /**
     * 查询活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取活动报名列表")
    public TableDataInfo<List<ActivityRegistration>> list(ActivityRegistration activityRegistration)
    {
        startPage();
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationList(activityRegistration);
        return getDataTable(list);
    }

    /**
     * 导出活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:export')")
    @Log(title = "活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出活动报名列表")
    public void export(HttpServletResponse response, ActivityRegistration activityRegistration)
    {
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationList(activityRegistration);
        ExcelUtil<ActivityRegistration> util = new ExcelUtil<ActivityRegistration>(ActivityRegistration.class);
        util.exportExcel(response, list, "活动报名数据");
    }

    /**
     * 获取活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取活动报名详细信息")
    public R<ActivityRegistration> getInfo(@ApiParam(value = "活动报名ID", required = true)
            @PathVariable("id") Long id) {
        return R.ok(activityRegistrationService.selectActivityRegistrationById(id));
    }

    /**
     * 新增活动报名
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:add')")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增活动报名")
    public AjaxResult add(@ApiParam(value = "活动报名实体", required = true) @RequestBody ActivityRegistration activityRegistration) {
        return activityRegistrationService.insertActivityRegistration(activityRegistration);
    }

    /**
     * 修改活动报名
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:edit')")
    @Log(title = "活动报名", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改活动报名")
    public AjaxResult edit(@ApiParam(value = "活动报名实体", required = true) @RequestBody ActivityRegistration activityRegistration)
    {
        return toAjax(activityRegistrationService.updateActivityRegistration(activityRegistration));
    }

    /**
     * 删除活动报名
     */
    @PreAuthorize("@ss.hasPermi('activity:registration:remove')")
    @Log(title = "活动报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除活动报名")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(activityRegistrationService.deleteActivityRegistrationByIds(ids));
    }
}
